import store from "@/store";
import request from "@/utils/request";



/**
 * 登录
 * @param {string} mobile 手机号
 * @param {string} code 验证码
 * @returns Promise
 * 
 */

export const loginAPI = (mobile , code) => {
    return request({
        url:'/v1_0/authorizations',
        method:'POST',
        data:{
            mobile,
            code
        }
    })
}


export const getCodeAPI = (mobile) => {
    return request ({
        url: `/v1_0/sms/codes/${mobile}`
    })
}

export const getUserInfoAPI = () =>{
   return request({
     url: '/v1_0/user',
    //  headers:{
    //      Authorization: `store.state.tokenObj.token`
    //  }
   })

}


export const getUserProfileAPI = () => {
    return request({
        url: '/v1_0/user/profile'
    })
}


/**
 *  修改用户信息 修改哪个就传哪个参数
 * @param {*} data {name , gender , birthday}
 * @returns Promise
 */

export const editUserProfileAPI = (data) => {
    return request({
        url: '/v1_0/user/profile',
        method: 'PATCH',
        data
     })
}


/**
 * 上传头像
 * @param {*} file 图片的文件对象
 * @returns 
 */
export const uploadPhoto = (file) => {
    const fm = new FormData()
    fm.append('photo', file)

    return request({
        url: 'v1_0/user/photo',
        method: 'PATCH',
        data: fm
    })
}